// Login Service

$(document).ready(function() {
	$("button").button( { icons: { primary: "ui-icon-triangle-1-e", secondary: null } });
	
	
    $('#loginForm').submit(function(e) {
		e.preventDefault();
		var username = $('#username').val();
		var password = CryptoJS.SHA3($('#password').val());
		var formData = 'username='+username+'&password='+password; 
		if(username != '' && password != '') {
		  $.ajax({
			  url: '/workspace/kilometerpauschale/backend/login/login.php',
			  data: formData,
			  type: 'POST',
			  dataType: "json"
		  }).done(function(data) {
			  
			  //alert(data);
			  if (data = 'success') {
				  window.location.href = "/workspace/kilometerpauschale/frontend/erfassung.html";
			  };
			  
		  }).fail(function(data) {
			  //alert(data);
		  });
		
		}
		
	});
});
